<?php
namespace app\ebcms\controller;
class Datadictcate extends \app\ebcms\controller\Common
{

    public function add()
    {
        if (request()->isGet()) {
            return \ebcms\Form::fetch();
        } elseif (request()->isPost()) {
            $obj = new \app\ebcms\model\Datadictcate();
            if (false !== $obj ->validate('Datadictcate.add')->save(input())) {
                $this -> success('操作成功！');
            }else{
                $this -> error($obj -> getError());
            }
        }
    }

    public function edit()
    {
        if (request()->isGet()) {
            $obj = \app\ebcms\model\Datadictcate::get(input('id'));
            return \ebcms\Form::fetch($obj);
        } elseif (request()->isPost()) {
            $obj = \app\ebcms\model\Datadictcate::get(input('id'));
            if (false !== $obj -> validate('Datadictcate.edit') -> isUpdate(true) -> save(input())) {
                $this -> success('操作成功！');
            }else{
                $this -> error($obj -> getError());
            }
        }
    }

    public function resort(){
        \app\ebcms\model\Datadictcate::where('id',input('id')) -> setField('sort',input('value'));
        $this -> success('操作成功！');
    }

    public function delete()
    {
        $items = \app\ebcms\model\Datadictcate::where(['id'=>['in',input('ids')]]) -> select();
        foreach ($items as $key => $obj) {
            $obj -> datadict() -> delete();
            $obj -> delete();
        }
        $this -> success('删除成功！');
    }

}